* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #1a1a1a;
    font-family: Arial, sans-serif;
}

.game-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    perspective: 1000px;
}

.card {
    position: relative;
    width: 100px;
    height: 100px;
    transform-style: preserve-3d;
    transition: transform 0.5s;
    cursor: pointer;
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

.front {
    background: #2196f3;
    transform: rotateY(180deg);
}

.back {
    background: #ff4081;
}

.card:focus {
    outline: none;
    transform: rotateY(180deg);
}

.card:focus ~ .card:focus {
    transform: rotateY(0deg);
}

.card:nth-child(2n):focus ~ .card:nth-child(2n):focus {
    background: #4caf50;
}

/* Match pairs using tabindex and focus states */
.card[data-match="1"]:focus ~ .card[data-match="1"]:focus,
.card[data-match="2"]:focus ~ .card[data-match="2"]:focus,
.card[data-match="3"]:focus ~ .card[data-match="3"]:focus,
.card[data-match="4"]:focus ~ .card[data-match="4"]:focus,
.card[data-match="5"]:focus ~ .card[data-match="5"]:focus,
.card[data-match="6"]:focus ~ .card[data-match="6"]:focus,
.card[data-match="7"]:focus ~ .card[data-match="7"]:focus,
.card[data-match="8"]:focus ~ .card[data-match="8"]:focus {
    transform: rotateY(180deg);
    pointer-events: none;
}

/* Matched cards styling */
.card:focus:valid {
    transform: rotateY(180deg) scale(0.95);
    opacity: 0.8;
}

@media (max-width: 500px) {
    .game-container {
        grid-template-columns: repeat(3, 1fr);
    }
    .card {
        width: 80px;
        height: 80px;
    }
}